<%@page pageEncoding="UTF-8"%>
<%@ taglib uri="/WEB-INF/taglib139.tld" prefix="pg" %>
<%@page contentType="text/html" import="java.util.Collection, Bean.*"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 
<%--
The taglib directive below imports the JSTL library. If you uncomment it,
you must also add the JSTL library to the project. The Add Library... action
on Libraries node in Projects view can be used to add the JSTL 1.1 library.
--%>
<%--
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 
--%>
<%
if(session.getAttribute("un")==null){
    response.sendRedirect("indexAdmin.jsp?page=Admin&url=Login");
    out.println("You must be login..!");
}else{%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<script language="javascript" type="text/javascript" src="../script/validate.js"></script>
<script language="javascript">
       function kiemtra(){
            var examtime = document.form1.ExamTimes;
            var mark = document.form1.Marks;
            var dateexam = document.form1.txtdateexam;
            if( laChuoiRong(examtime.value))
            {
                alert('Exam time is not blank!');
                examtime.focus();
                return false;
            }
            if( laChuoiRong(mark.value))
            {
                alert('Mark is not blank!');
                mark.focus();
                return false;
            }
            if( laChuoiRong(dateexam.value))
            {
                alert('Date exam is not blank!');
                dateexam.focus();
                return false;
            }
            if(!laSoNguyen(examtime.value))
            {
                alert('Examtimes is number!');
                examtime.focus();
                return false;
            }
            if(!laso(mark.value))
            {
                alert('Mark is number!');
                mark.focus();
                return false;
            }
            if(mark.value>100)
            {
                alert('Mark must be greater than or equal to 0 and or equal to 100 !');
                mark.focus();
                return false;
            }
            if(!laNgay(dateexam.value))
            {
                alert('Date exam invail !');
                dateexam.focus();
                return false;
            }
       }
</script>       
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body> 
        <%
        StudentBean stu=new StudentBean();
        Collection kq=stu.getListStudent();
        request.setAttribute("st1", kq);
        
        String r="";String m="";String ma=""; String d=""; String drop="";
        if(session.getAttribute("exameID")!=null){
            r=session.getAttribute("exameID").toString();
            m=session.getAttribute("examTime").toString();
            ma=session.getAttribute("mark").toString();
            d=session.getAttribute("date").toString();
            drop=session.getAttribute("subject").toString();
        }
        %>
        <%
        SubjectBean subject=new SubjectBean();
        Collection sub=subject.getListSubject();
        request.setAttribute("sts", sub);
        %>
        <form action="../ControllExamMark" method="post" name="form1" onsubmit="return kiemtra()">
            <h3 align="center">Exam Marks management</h3>
            <table>
                <input type="hidden" name="exameID" value="<%=r%>" />
                <tr>
                    <td>Rollno:</td>
                    <td>
                        
                        <select name="roll">
                            <c:forEach items="${st1}" var="student">
                                <option value="${student.rollno}">${student.rollno}</option>
                            </c:forEach>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td>SubID:</td>
                    <td>
                    <%--    <%if(drop!=null){
                        
                        %>--%>
                        <select name="subid">
                            <c:forEach items="${sts}" var="subj">
                              <%--   <% if(drop.equals(subj.subID)){%>
                                <option selected="selected" value="${subj.subID}">${subj.subID}</option>
                                <%}%>--%>
                                <option selected="selected" value="${subj.subID}">${subj.subID}</option>
                            </c:forEach>
                            
                        </select>
                        <%-- <%}%>--%>
                    </td>
                </tr>
                <tr>
                    <td>ExamTimes:</td>
                    <td><input type="text" name="ExamTimes" value="<%=m%>" /></td>
                </tr>
                <tr>
                    <td>Marks:</td>
                    <td><input type="text" name="Marks" value="<%=ma%>" /></td>
                </tr>
                <tr>
                    <td>Date Exam:</td>
                    <td><input type="text" name="txtdateexam" value="<%=d%>" /> (MM/dd/yyyy)</td>
                </tr>
                <tr>
                    <td></td>
                    <td>
                        <input type="submit" name="bt" value="Insert" />
                        <input type="submit" name="bt" value="Update" />
                        <input type="button" name="btreset" value="Reset" onclick="clear_fields()" />
                    </td>
                </tr>
            </table>
            
            <%
            ExamMarkBean exam=new ExamMarkBean();
            Collection kq1=exam.getListExamMark();
            request.setAttribute("st", kq1);
            %>
            
            <table border="1">
                <tr>
                    <td colspan="8"><a href="indexAdmin.jsp?page=Admin&url=SearchExamMarks">Search Exam Marks</a></td>
                </tr>
                <tr>
                    <th>Rollno</th>
                    <th>SubID</th>
                    <th>ExamTimes</th>
                    <th>Marks</th>
                    <th>Date Exam</th>
                    <th colspan="2">Action</th>
                </tr>
                <pg:paging pageSize="10" url="indexAdmin.jsp?page=Admin&url=user">
                    <c:forEach items="${st}" var="s">
                        <pg:item> 
                            <tr>
                                <td><c:out value="${s.rollno}" /></td>
                                <td>${s.subid}</td>
                                <td>${s.examTime}</td>
                                <td>${s.mark}</td>
                                <td>${s.dateexam}</td>
                                <c:url var="delete" value="../ControllExamMark">
                                    <c:param name="bt" value="Delete" />
                                    <c:param name="exameID" value="${s.id}" />
                                    <c:param name="p" value="${param.pageNum}"/>
                                </c:url>
                                <c:url var="edit" value="../ControllExamMark">
                                    <c:param name="bt" value="Edit" />
                                    <c:param name="exameID" value="${s.id}" />
                                    <c:param name="examTime" value="${s.examTime}" />
                                    <c:param name="mark" value="${s.mark}" />
                                    <c:param name="dateexm" value="${s.dateexam}" />
                                    <c:param name="sb" value="${s.subid}" />
                                    <c:param name="p" value="${param.pageNum}"/>
                                </c:url>
                                <% if(session.getAttribute("permission")!=null){
                if(session.getAttribute("permission").equals("Academic")){%>
                                <td><a href="${edit}">Edit</a></td>
                                <%    
                                }
                                %>
                                <% 
                                if(session.getAttribute("permission").equals("Admin")){%>
                                <td><a href="${edit}">Edit</a></td>
                                <td><a href="${delete}" onclick="return confirm('Do you really want to delete these records ?')">Delete</a></td>
                                <%    
                                }
                                %>
                                <%}%>
                            </tr>
                        </pg:item> 
                    </c:forEach>  
                    <pg:index>
                        <pg:page><%=thisPage%></pg:page>
                        <pg:firstPage>[First]</pg:firstPage>
                        <pg:lastPage>[Last]</pg:lastPage> 
                    </pg:index> 
                </pg:paging> 
            </table>
        </form>
    </body>
</html>
<%}%>
